package com.apptest.android.ui.common;

import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel;

import com.apptest.android.core.Constants;
import com.apptest.android.core.bean.ArticleListBean;
import com.apptest.android.core.bean.SubordinateTitleBean;
import com.apptest.android.core.bean.WxBloggerBean;
import com.apptest.android.core.network.ApiEngine;
import com.apptest.android.core.network.BaseObserver;

import java.util.ArrayList;
import java.util.List;

public class SubordinatePageViewModel extends ViewModel {
    private MutableLiveData<List<SubordinateTitleBean>> subordinateTitleList;

    public SubordinatePageViewModel(){
        subordinateTitleList = new MutableLiveData<>();
    }

    public LiveData<List<SubordinateTitleBean>> getSubordinateTitleList() {
        return subordinateTitleList;
    }

    public void updateSubordinateTitleList(int pageSource) {
        switch (pageSource) {
            case Constants.ARTICLE_FROM_WECHAT:
                ApiEngine.getWxBloggerList(new BaseObserver<List<WxBloggerBean>>() {
                    @Override
                    public void onSuccess(List<WxBloggerBean> wxBloggerBeans) {
                        List<SubordinateTitleBean> temp = new ArrayList<>();
                        for(WxBloggerBean bean:wxBloggerBeans){
                            SubordinateTitleBean titleBean = new SubordinateTitleBean(
                                    bean.getId(),
                                    bean.getName()
                            );
                            temp.add(titleBean);
                        }
                        subordinateTitleList.setValue(temp);
                    }
                });
                break;
            case Constants.ARTICLE_FROM_ARCHITECTURE:
            default:
                break;
        }
    }

    public void setSubordinateTitleList(List<SubordinateTitleBean> list){
        subordinateTitleList.setValue(list);
    }
}
